import Vue from 'vue'
import VueRouter from 'vue-router'
//路由懒加载优化
const Login = () => import(/* webpackChunkName: "Login_home_welcome" */ '../components/login.vue')
const home = () => import(/* webpackChunkName: "Login_home_welcome" */ '../components/home.vue')
const welcome = () => import(/* webpackChunkName: "Login_home_welcome" */ '../components/welcome.vue')

// import Login from "../components/login.vue"
// import home from '../components/home.vue'
// import welcome from '../components/welcome.vue'
const users = () => import(/* webpackChunkName: "users_roles_right " */ '../components/user/users.vue')
const roles = () => import(/* webpackChunkName: "users_roles_right " */ '../components/roles.vue')
const right = () => import(/* webpackChunkName: "users_roles_right " */ '../components/power/right.vue')
// import users from '../components/user/users.vue'
// import roles from '../components/roles.vue'
// import right from '../components/power/right.vue'
const Cate = () => import(/* webpackChunkName: "Cate_params " */ '../components/goods/Cate.vue')
const params  = () => import(/* webpackChunkName: "Cate_params " */ '../components/goods/params.vue')
// import Cate from '../components/goods/Cate.vue'
// import params from '../components/goods/params.vue'
const lister = () => import(/* webpackChunkName: "lister_ack_orders_reports " */ '../components/goods/list.vue')
const ack = () => import(/* webpackChunkName: "lister_ack_orders_reports " */ '../components/goods/add.vue')
const orders = () => import(/* webpackChunkName: "lister_ack_orders_reports " */ '../components/order/orders.vue')
const reports = () => import(/* webpackChunkName: "lister_ack_orders_reports " */ '../components/Reports/reports.vue')
// import lister from '../components/goods/list.vue'
// import ack from '../components/goods/add.vue'
// import orders from '../components/order/orders.vue'
// import reports from '../components/Reports/reports.vue'
Vue.use(VueRouter)

const router = new VueRouter({
  routes:[
    {path:'/',redirect:'/login'},
    {path:'/login',
    component:Login},
    {path:'/home',component:home,
    redirect:'/welcome',
    children:[{path:'/welcome',component:welcome},{path:'/users', component:users},{path:'/roles', component:roles},
    {path:'/rights',component:right}, {path:'/categories',component:Cate},{path:'/params',component:params},
    {path:'/goods',component:lister},{path:'/goods/add',component:ack},{path:'/orders',component:orders},
    {path:'/reports',component:reports}
  ]},


  ]
})


router.beforeEach((to,from,next)=>{
       if(to.path==='/login') return next()
   const tokenStr =window.sessionStorage.getItem('token')
       if(!tokenStr) return next('login')
       next()
})

export default router
